package com.crois.barrier.web.support;


import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;

/**
 * @author Hou Ze Yu
 * @description Server WebExchange 公共类
 * @date 2020/7/19
 */
public class ServerWebExchangeUtils {

    public static final String START_TIME = "startTime";

   public static final String BARRIER_REQUEST_URL_ATTR = "barrier_request_url";

   public static final String BARRIER_REQUEST_PATH = "barrier_request_path";

   public static final String BARRIER_ROUTE_ATTR = "barrier_route";

   public static final String BARRIER_SCHEME_PREFIX_ATTR = "gateway_scheme_prefix";

    public static final String HTTP_TIME_OUT = "http_time_out";

    public static final String RETRY_TIMES = "retry_times";

    public static final String BARRIER_CLIENT_RESPONSE_ATTR = "barrier_gateway_response";

    public static final String BARRIER_CLIENT_RESPONSE_RESULT_TYPE = "barrier_client_response_result";

    public static final String BARRIER_CLIENT_RESPONSE_CONN_ATTR = "barrier_gateway_response_connection";

    public static final String BARRIER_RESPONSE_CONTENT_TYPE_ATTR = "barrier_gateway_response_contentType";

    public static final String BARRIER_HTTP_TYPE = "barrier_gateway_http_type";

    /**
     * Client response header names attribute name.
     */
    public static final String CLIENT_RESPONSE_HEADER_NAMES = "gatewayClientResponseHeaderNames";

    public static final String BARRIER_REQUEST_EXECUTE_TIME = "request_execute_time";


    public static boolean containsEncodedParts(URI uri) {
      boolean encoded = uri.getRawQuery() != null && uri.getRawQuery().contains("%") || uri.getRawPath() != null && uri.getRawPath().contains("%");
      if (encoded) {
         try {
            UriComponentsBuilder.fromUri(uri).build(true);
            return true;
         } catch (IllegalArgumentException var3) {
            return false;
         }
      } else {
         return encoded;
      }
   }
}
